package com.javabaas.server.novel_server.hotWords.controller;

import com.javabaas.server.novel_server.common.ModuleCode;
import com.javabaas.server.novel_server.common.ResponseJson;
import com.javabaas.server.novel_server.common.StatusCode;
import com.javabaas.server.novel_server.hotWords.service.HotWordService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;

@RestController
@RequestMapping(value = "/hot_words")
public class HotWordController {



    @Autowired
    HotWordService hotWordService;


    @RequestMapping(value = "", method = RequestMethod.GET)
    @ApiOperation(value = "获取搜索热词", notes = "")
    public Object searchHotwords() {
        return hotWordService.searchHotWords();
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    @ApiOperation(value = "上传搜索的词", notes = "")
    @ApiImplicitParam(name = "hotWord", value = "搜索的词", required = true, dataType = "String", paramType = "query")
    public Object insertHotWords(HttpServletRequest request) {
        String hotWord = request.getParameter("hotWord");
        boolean result = hotWordService.uploadHotWords(hotWord);
        return ResponseJson.getResponseJson(ModuleCode.MODULE_BOOK_STATUS, StatusCode.STATUS_OK, result);
    }
}
